package tree.leetcode_96_medium_dp;

public class NumTrees {
    public static void main(String[] args) {
        numTrees(3);
    }
    public static int numTrees(int n) {
        if(n < 0){
            return 0;
        }
        int[] dp = new int[n + 1];

        dp[0] = 1;
        dp[1] = 1;
        for (int i = 2; i <= n; i++){
            //根节点占用1个节点，所以要 - 1
            for (int j = 0; j <= i - 1; j++){
                dp[i] += dp[j] * dp[i - j - 1];
            }
        }
        return dp[n];
    }
}
